#pragma once

#include <unordered_map>

#include "common/json.h"
#include "common/re.h"
#include "messaging/dispatcher.h"
#include "messaging/endpoint.h"


namespace evm { namespace messaging {

using namespace std;
using namespace re;

/* Filter notification messages.
 *
 * The NotificationFilter class is used to filter notifications that an
 * endpoint will received.
 *
 * The notification can be filter on different fields:
 * publisher_id, event_type, metadata and payload.
 *
 * The filter is done via regular expressions.
 * Especially, payload must be mapping from **string** key to regular expression value.
 *
 * filter_rule =  NotifyFilter({
 *   {"publisher_id", "^compute.*"},
     {"event_type", R"re(^compute\.instance\..*)re"},
     {"timestamp", "Aug"},
     {"payload", {{"state", "^active$"}}
   }
 */
struct NotifyFilter : Filter {
    NotifyFilter(const Json& args);

    bool match(const Json& args);

    RegexPtr publisher_id;
    RegexPtr event_type;
    RegexPtr timestamp;
    unordered_map<string, RegexPtr> payload;
};

using NotifyFilterPtr = shared_ptr<NotifyFilter>;

}}
